<#assign primaryKeyType = columns?filter(column -> column.primary)?first.javaType>
<#--  拿到主键类型 -->
package ${packageName}.service.impl;

import org.springframework.stereotype.Service;
import ${packageName}.domain.${className};
import ${packageName}.domain.${className}Repository;
import ${packageName}.service.*;

import vip.liux.application.dots.ListResultDto;
import vip.liux.application.dots.PagedResultDto;
import static vip.liux.application.PageKit.toPage;
import static vip.liux.application.PageKit.toPaged;

@Service
public class ${className}ServiceImpl implements ${className}Service {
private final ${className}Repository repository;

public ${className}ServiceImpl(${className}Repository repository) {
this.repository = repository;
    }

    @Override
public PagedResultDto
<${className}Dto> pageList(Query${className}Dto input) {
    return toPaged(repository.findAll(toPage(input)).map(AutoMapperProfile.INSTANCE::toDto));
    }

    @Override
    public ${className}Dto save(Create${className}Dto input) {
    // todo query by params ?
    return AutoMapperProfile.INSTANCE.toDto(
    repository.save(AutoMapperProfile.INSTANCE.toEntity(input))
    );
    }

    @Override
    public ListResultDto
    <${className}Dto> allList() {
        return new ListResultDto<>(
        AutoMapperProfile.INSTANCE.toDto(repository.findAll())
        );
    }

        @Override
        public ListResultDto
        <${className}Dto> list(Query${className}Dto input) {
            // todo query by params ?
            return new ListResultDto<>(
            AutoMapperProfile.INSTANCE.toDto(repository.findAll())
            );
            }

            @Override
            public ${className}Dto detail(${primaryKeyType} id) {
            return AutoMapperProfile.INSTANCE.toDto(
            repository.findById(id)
            .orElseThrow(()-> new IllegalArgumentException("Entity not found with id: " + id))
            );
            }

    @Override
    public ${className}Dto update(${primaryKeyType} id, Update${className}Dto input) {
            ${className} entity = repository.findById(id)
            .orElseThrow(() -> new IllegalArgumentException("Entity not found with id: " + id));
            AutoMapperProfile.INSTANCE.toEntity(entity, input);
            return AutoMapperProfile.INSTANCE.toDto(repository.save(entity));
    }

    @Override
    public void delete(${primaryKeyType} id) {
            repository.deleteById(id);
    }
            }